package com.cleaningcloud.cld.service.impl;

import com.cleaningcloud.cld.domain.CldPayConfirm;
import com.cleaningcloud.cld.domain.dto.CldPayConfirmDto;
import com.cleaningcloud.cld.domain.excelExport.SalaryExcelExport;
import com.cleaningcloud.cld.mapper.CldPayConfirmMapper;
import com.cleaningcloud.cld.service.ICldPayConfirmService;
import com.cleaningcloud.common.core.utils.DateUtils;
import com.cleaningcloud.common.core.utils.StringUtils;
import com.cleaningcloud.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 薪酬确认Service业务层处理
 *
 * @author cleaningcloud
 * @date 2024-11-21
 */
@Service
public class CldPayConfirmServiceImpl implements ICldPayConfirmService {
    @Autowired
    private CldPayConfirmMapper cldPayConfirmMapper;

    /**
     * 查询薪酬确认
     *
     * @param payConfirmId 薪酬确认主键
     * @return 薪酬确认
     */
    @Override
    public CldPayConfirm selectCldPayConfirmByPayConfirmId(Long payConfirmId) {
        return cldPayConfirmMapper.selectCldPayConfirmByPayConfirmId(payConfirmId);
    }

    /**
     * 查询薪酬确认列表
     *
     * @param cldPayConfirm 薪酬确认
     * @return 薪酬确认
     */
    @Override
    public List<CldPayConfirm> selectCldPayConfirmList(CldPayConfirm cldPayConfirm) {
        return cldPayConfirmMapper.selectCldPayConfirmList(cldPayConfirm);
    }

    @Override
    public List<SalaryExcelExport> selectSalaryExcelExport(SalaryExcelExport salaryExcelExport) {
        return cldPayConfirmMapper.selectSalaryExcelExport(salaryExcelExport);
    }

    /**
     * 新增薪酬确认
     *
     * @param cldPayConfirm 薪酬确认
     * @return 结果
     */
    @Override
    public int insertCldPayConfirm(CldPayConfirm cldPayConfirm) {
        cldPayConfirm.setCreateTime(DateUtils.getNowDate());
        return cldPayConfirmMapper.insertCldPayConfirm(cldPayConfirm);
    }

    /**
     * 修改薪酬确认
     *
     * @param cldPayConfirm 薪酬确认
     * @return 结果
     */
    @Override
    public int updateCldPayConfirm(CldPayConfirm cldPayConfirm) {
        return cldPayConfirmMapper.updateCldPayConfirm(cldPayConfirm);
    }

    /**
     * 批量删除薪酬确认
     *
     * @param payConfirmIds 需要删除的薪酬确认主键
     * @return 结果
     */
    @Override
    public int deleteCldPayConfirmByPayConfirmIds(Long[] payConfirmIds) {
        return cldPayConfirmMapper.deleteCldPayConfirmByPayConfirmIds(payConfirmIds);
    }

    /**
     * 删除薪酬确认信息
     *
     * @param payConfirmId 薪酬确认主键
     * @return 结果
     */
    @Override
    public int deleteCldPayConfirmByPayConfirmId(Long payConfirmId) {
        return cldPayConfirmMapper.deleteCldPayConfirmByPayConfirmId(payConfirmId);
    }

    @Override
    public int confirmIssuance(CldPayConfirmDto cldPayConfirmDto) {
        if (StringUtils.isNull(cldPayConfirmDto.getProjectIds()) && StringUtils.isNull(cldPayConfirmDto.getStaffIds())) {
            throw new RuntimeException("请选择项目或者员工");
        }
        cldPayConfirmDto.setSendUserId(SecurityUtils.getUserId());
        return cldPayConfirmMapper.confirmIssuance(cldPayConfirmDto);
    }
}
